home *** CD-ROM | disk | FTP | other *** search
- // OptParms.lib - Library for the OptionalParameter() routine: to
- // ver.1 parse optional paramters from the input to a
- // Cmm program.
- //
- // Arguments are case-insentitive and can take any of these forms:
- // Program /SETTING VALUE
- // Program /SETTING=VALUE
- // Program -SETTING VALUE
- // Program -SETTING=VALUE
- // Program /BOOL
- // Program -BOOL
- //
- //
- // SYNTAX: bool OptionalParameter(argc,argv,Setting[,Value])
- // WHERE: argc: argument count, as in main(argc,argv)
- // argv: input arguments, as in main(argc,argv)
- // Setting: case-insensitive string to match arguments
- // Value: optional input to get value following Setting.
- // If Value is not supplied then Settings is a boolean
- // RETURN: TRUE if Setting[Value] found, and sets Value and adjusts
- // argc and argv; else returns FALSE and no arguments changed
- //
-
- OptionalParameter(iArgC,iArgV,iSetting,iValue)
- {
- BoolSetting = ( va_arg() < 4 );
- RemoveArgCount = 1; // default
- SettingLen = strlen(iSetting);
- for ( _i = 1; _i < iArgC; _i++ ) {
- if ( strchr("/-",iArgV[_i][0]) ) {
- _Setting = iArgV[_i] + 1;
- if ( !strnicmp(iSetting,_Setting,SettingLen) ) {
- switch ( _Setting[SettingLen] ) {
- case 0:
- if ( BoolSetting ) {
- RemoveMainArg(iArgC,iArgV,_i);
- return( TRUE );
- }
- if ( _i < (iArgC - 1) ) {
- // Next argument is value for this setting
- RemoveMainArg(iArgC,iArgV,_i);
- strcpy(iValue,iArgV[_i]);
- RemoveMainArg(iArgC,iArgV,_i);
- return(TRUE);
- }
- break;
- case '=':
- if ( !BoolSetting ) {
- strcpy(iValue,_Setting + SettingLen + 1);
- RemoveMainArg(iArgC,iArgV,_i);
- return(TRUE);
- }
- break;
- }
- }
- }
- }
- return( FALSE );
- }
-
-
- RemoveMainArg(iArgC,iArgV,iIndex) // remove iIndex indexed arg
- {
- for ( _i = iIndex; _i < iArgC; _i++ ) {
- iArgV[_i] = iArgV[_i+1];
- }
- iArgC--;
- }
-